<#assign className = table.className>   
<#assign classNameLower = className?uncap_first>
package ${basepackage}.${namespace};

import com.jfinal.plugin.activerecord.Page;
import com.fc.component.base.BaseProjectController;
import com.fc.jfinal.component.db.SQLUtils;
import com.fc.util.StrUtils;
import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Page;


@Path("/admin/${namespace}")
public class ${className}Controller extends BaseProjectController {

	private static final String path = "/pages/admin/${namespace}/${namespace}_";

	public void list() {
		${className} model = getModelByAttr(${className}.class);
		SQLUtils sql = 	new SQLUtils(" from ${table.constantName} t where 1=1 ");
		if (model.getAttrValues().length != 0) {
			sql.setAlias("t");
			// 查询条件
//			sql.whereLike("username", model.getStr("username"));

		}
		// 排序
		String orderBy = getBaseForm().getOrderBy();
		if (StrUtils.isEmpty(orderBy)) {
			sql.append(" order by t.id desc ");
		} else {
			sql.append(" order by ").append(orderBy);
		}

		Page<${className}> page = ${className}.dao.paginate(getPaginator(), "select t.* ", //
				sql.toString().toString());

		// 下拉框
		setAttr("page", page);
		setAttr("attr", model);
		render(path + "list.html");
	}

	public void add() {
		
		render(path + "add.html");
	}

	public void view() {
		${className} model = ${className}.dao.findById(getParaToInt());
		setAttr("model", model);
		render(path + "view.html");
	}

	public void delete() {
		
		${className} model = new ${className}();
		Integer userid= getSessionUser().getUserID();
		String now = getNow();
		model.put("update_id", userid);
		model.put("update_time", now);
		model.deleteById(getParaToInt());
		
		list();
	}

	public void edit() {

		${className} model = ${className}.dao.findById(getParaToInt());
		setAttr("model", model);
		render(path + "edit.html");
	}

	public void save() {
		Integer pid = getParaToInt();
		${className} model = getModel(${className}.class);

		Integer userid = getSessionUser().getUserID();
		String now = getNow();
		model.put("update_id", userid);
		model.put("update_time", now);
		if (pid != null && pid > 0) { // 更新
			model.update();
		} else { // 新增
			model.remove("id");
			model.put("create_id", userid);
			model.put("create_time", now);
			model.save();
		}
		renderMessage("保存成功");
	}

}
